package com.forte.cartservice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.forte.cartdao.Cart;
import com.forte.cartdao.CartDAO;
import com.forte.cartdao.CartProduct;
import com.forte.exception.InvalidParameterException;
import com.forte.productdao.Product;
import com.forte.shoppingcustomerdao.ShoppingCustomer;


public class CartServiceImpl implements CartService{
	
	@Autowired
	@Qualifier("cartDAO")
	private CartDAO cartDao;
	
	public void setCartDAO(CartDAO cartDao){
		this.cartDao = cartDao;
	}

	public void addToCart(Cart cart, Product product, int quantity)
			throws InvalidParameterException {
		cartDao.addToCart(cart, product, quantity);		
	}

	public void saveOrUpdate(ShoppingCustomer customer) {
		cartDao.saveOrUpdate(customer);		
	}

	public void saveOrUpdate(CartProduct cartProduct) {
		cartDao.saveOrUpdate(cartProduct);		
	}

	public void saveOrUpdate(Cart cart) {
		cartDao.saveOrUpdate(cart);		
	}

	public Cart findCartById(int userId) {
		return cartDao.findCartById(userId);
	}

	public Cart findCartByCartId(int cartId) {
		return cartDao.findCartByCartId(cartId);
	}

	public CartProduct findCartAndProductInCartProduct(int userId, int productId) {
		return cartDao.findCartAndProductInCartProduct(userId, productId);
	}

	public void removeProductFromCart(Cart cart, Product product) {
		 cartDao.removeProductFromCart(cart, product);		
	}

	public void changeProductQuantityInCart(Cart cart, Product product,
			int quantity) throws InvalidParameterException {
		cartDao.changeProductQuantityInCart(cart, product, quantity);		
	}

	public double computeTotalValue(Cart cart) {
		return cartDao.computeTotalValue(cart);
	}

}
